package hn.cch.controller;

import hn.cch.entity.Product;
import hn.cch.message.Response;
import hn.cch.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "product")
@RestController
public class ProductController {

    public static Logger logger = LoggerFactory.getLogger(ProductController.class);

    @Autowired
    private ProductService productService;

    // public String getAll(){
    //
    // }

    @GetMapping(value = "getOne/{id}")
    public Product getOne(@PathVariable Integer id){
        logger.info("getOne");
        return productService.findById(id);
    }


    @PostMapping(value = "setOne")
    public Product setOne(Product product){
        logger.info("getOne");
        return productService.save(product);
    }


    @GetMapping(value = "subAny/{id}/{stock}")
    public Response<Product> subAny(@PathVariable Integer id, @PathVariable Integer stock){
        logger.info("subAny");
        return productService.subAny(id, stock);
    }
}
